<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>修改商品</title> $!{include("import_js_css.html")}
<!-- #set(Goods goods) -->
<script>
$(function(){
	$("#selGoodsType").val('${goods.type}');
});
</script>
</head>
<body>
	$!{include("header.html")}
	<div class="menu_all">
		<div class="div_search_result clear">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">修改商品</h3>
			</div>
			<div class="panel-form-add">
				<form class="form-horizontal" name="goodsForm" role="form" action="yueyogaAdmin/updateGoods.jhtml" method="POST">
					<div class="panel-form-layout">
					    <label for="txtGoodsName" class="col-sm-1 control-label">商品名称</label>
						<div class="col-sm-3">
							<input type="text" required class="form-control" name="name" id="txtGoodsName" value="${goods.name}" >
						</div>
						<label for="selGoodsType" class="col-sm-1 control-label">商品类型</label>
						<div class="col-sm-3">
							<!--#var(GoodType type,List<GoodType> types)-->
							<select class="selectpicker show-menu-arrow" data-width="100%" name="type" id="selGoodsType">
								<option value="">请选择</option>
								<!--#foreach(type in types)-->
								<option value="${type.id}">${type.name}</option>
								<!-- #end -->
							</select>
						</div>
						<br /> <br /> <label for="txtPrice" class="col-sm-1 control-label">商品价格</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" onkeyup="clearNoNumOfAlert(this)" value="${goods.price}" required name="price" id="txtPrice" >
						</div>
						<div id="div_counts">
							<label for="txtProductCounts" class="col-sm-1 control-label">商品库存</label>
							<div class="col-sm-3">
								<input type="text" class="form-control" required name="counts" id="txtCounts" value="${goods.counts}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
							</div>
						</div>
						<br /> <br /> <label for="txtRemarks" class="col-sm-1 control-label">商品备注</label>
						<div class="col-sm-3">
							<textarea class="form-control panel-form-address" name="remarks" id="txtRemarks" >${goods.remarks}</textarea>
						</div>
						<input type="hidden" value="${goods.id}" name="id"/>
						<br> <br> <br> <br>
						<div class="panel-btn-search">
							<button type="submit" class="btn btn-default btn-ade-default panel-mr">保存</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	function documentReady() {
		var msg = '${msg}';
		if (msg == 'ugf') {
			error("修改商品失败!");
		}
		$("#selProductType").change(
				function() {
					var type = $(this).val();
					if (type == '1') {
						$("#div_datetime").hide();
						$("#div_counts").show();
					} else if (type == '2') {
						$("#div_counts").hide();
						$("#div_datetime").show();
					} else if (type == '3' || type == '4' || type == '5'
							|| type == '6') {
						$("#div_counts").hide();
						$("#div_datetime").hide();
					}
				});
		
		
		//去掉下拉输入框
		$("#selGoodsType").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
	};

	function clearNoNumOfAlert(obj) {

		//得到第一个字符是否为负号
		var t = obj.value.charAt(0);
		//先把非数字的都替换掉，除了数字和.   
		obj.value = obj.value.replace(/[^\d.]/g, "");
		//必须保证第一个为数字而不是.   
		obj.value = obj.value.replace(/^\./g, "");
		//保证只有出现一个.而没有多个.   
		obj.value = obj.value.replace(/\.{2,}/g, ".");
		//保证.只出现一次，而不能出现两次以上   
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace(
				"$#$", ".");
		//如果第一位是负号，则允许添加
		if (t == '-') {
			obj.value = '-' + obj.value;
		}
	}
</script>
</html>
